<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CrearSolicitud
 *
 * @export Modules
 * export-metadata RequiredRoles:ROLE_ENTERPRISE:ROLE_PRACTICES_COORDINATOR
 */
Loader::using("ext::libs::FactoryEmail::SmtpMail");

class CrearSolicitud extends Module {
    /**
     *
     * @var Solicitudes 
     */
    private $Solicitud;


    public function index() {
        $usuario= $this->currentUser->getName();
        //con usuario obtener el nit
        $nit;
        $Empresa= $this->model->companies->GetById($nit);
        $PlanesEstudios = $this->model->career->GetByTipoPrograma(PlanesEstudios::PREGRADO, false);
        $Paises = $this->model->countries->GetAll(false);

        $this->assign("company", $Empresa);
        $this->assign("careers", $PlanesEstudios);
        $this->assign("Paises", $Paises);
        $this->assign("action", $this->route->action("Create"));
        $this->assign("AgregarEmpresa", $this->route->moduleAction("GestionEmpresas", "AgregarEmpresaGenerico", array("ajax" => true)));
        $this->assign("GetDepartamentos", $this->route->moduleAction("PublicData", "GetDepartamentoByPais", array("ajax" => "true", "IdPais" => "")));

        $this->assign("GetMunicipios", $this->route->moduleAction("PublicData", "GetMunicipio", array("ajax" => "true", "CodigoDepartamento" => "")));

        $this->display("index");
    }

    public function Create() {
        
        if ($this->request->submitted()) {

            Loader::using("models::entities::Solicitudes");
            $this->Solicitud = new Solicitudes();
            $this->Solicitud->setSolicitante(new Trabajadores());
            $this->Solicitud->setTutor(new Trabajadores());
            $this->request->bind($this->Solicitud);
            $this->model->applications->Create($this->Solicitud);
            
            $this->send();

            $this->addMessage(new Message("", "Solicitud Creada Correctamente", Message::SUCCESS));
    
            $this->display();
            
        } else {
            $this->index();
        }
    }

    public function send() {
            $emails = array();
            $emails[] = "boscaru@gmail.com";
            $message = "Cordial saludo. Una empresa ha solicitado un estudiante en practica. Para ver más datos acerca de la solicitud visita nuestra plataforma ";
            $subject = "Notificacion de solicitud de practicante";

            $Mail = new SmtpMail($message, $subject, $emails, "smtp.gmail.com", "manlioferreira@gmail.com", "loquesea");
            $Mail->SendMail();        
    }

}

?>
